<?php
class Library_Model_ChucVuMapper extends Library_Model_DataMapperAbstract{
	private static $_instance = null;
	private $_paginator = null;
	
	public function searchChucVuById($id)
	{
		$db = $this->getDb();
		$selectChucvu = $db->select()
							->from('tbl_chucvu')
							->where('MaChucVu = ?',$id);
		$chucvu = $db->fetchRow($selectChucvu);
		
		return $this->_populate($chucvu);
	
	}
	public function chucvuList()
	{
		$db = $this->getDb();
		$selectChucvu = $db->select()
						->from('tbl_chucvu');
		$chucvus = $db->fetchAll($selectChucvu);
	
		$chucvuObjArray = array();
		foreach($chucvus as $chucvu){			
			$chucvuObjArray[] = $this->_populate($chucvu);
		}
	
		return $chucvuObjArray;
	}
	
	public function _populate($data){
		$obj = new Library_Model_ChucVu();
		$obj->setId($data['MaChucVu']);
		$obj->setTenchucvu($data['TenChucVu']);
	
		return $obj;		
	}
	
	protected function _insert(Library_Model_DomainObjectAbstract $obj){	
		$db = $this->getDb();		
		$data =array(
				'MaChucVu' => $obj->getId(),
				'TenChucVu' => $obj->getTenchucvu(),				
				);
		$db->insert('tbl_chucvu',$data);
	}
	protected function _update(Library_Model_DomainObjectAbstract $obj){
		
		$db = $this->getDb();
		$data =array(
				'MaChucVu' => $obj->getId(),
				'TenChucVu' => $obj->getTenchucvu(),			
				);
		$where = $db->quoteInto('MaChucVu = ?', $obj->getId());
		$db->update('tbl_chucvu',$data,$where);
	}
	
	public function delete($id)
	{
		$db = $this->getDb();
		$where = $db->quoteInto('MaChucVu = ?',$id);
		$db->delete('tbl_chucvu',$where);
	}
	public static function getInstance(){
		if(!isset(self::$_instance)){
			$c = __CLASS__;
			self::$_instance = new $c;
		}
		return self::$_instance;
	}
	
	}